import './index.less'
import {checkInformation, getInformation} from "../../utils/network/network.config.js";
import {getElement, vendorsGetUrlParam} from '../../utils/network/networkutils'


let tenantname = getElement('tenantname');
let city = getElement('city');
let linkman = getElement('linkman');
let mobilephone = getElement('mobilephone');
let email = getElement('email');
let agree = getElement('agree');
let agreetoast = getElement('agreetoast');
let maketure = getElement('maketure');
let agreeclose = getElement('agreeclose');
let flag = true;
let billstatus;

let pkTrialInfo=vendorsGetUrlParam(window.location.href);
pkTrialInfo={...pkTrialInfo,ieStamp:new Date().getTime(), 'isAjax':1};
window.onload=function () {
    getInformation(pkTrialInfo).then(res=>{
        if (res.data.needrelogin){
            location.reload()
        }
        let resultCode=res.data.resultCode;
        if(resultCode === 'noLogin'){
            alert('请登录');
            window.location.href='/official-index.html';
        }else if (resultCode==='noAuth'){
            alert('没有权限');
            window.location.href='/official-index.html';
        }
        if (resultCode !== 'busi_ex') {
            bindinformation(res.data.result);
            billstatus=res.data.result.billstatus;
            repeatClick(billstatus)
        }
    })
};
function repeatClick() {
    if (billstatus===1){
        agree.style.cssText="display: block;";
    }else{
        agree.style.cssText="display: none;";
    }
}

function bindinformation(res) {
    tenantname.innerHTML=res.tenantname;
    city.innerHTML=res.province+res.city+res.county+res.detailaddress;
    linkman.innerHTML=res.linkman;
    mobilephone.innerHTML=res.mobilephone;
    email.innerHTML=res.email
}

agree.onclick=function () {
    if (flag) {
        flag = false;
        checkInformation({...pkTrialInfo, ieStamp: new Date().getTime(), 'isAjax': 1}).then((res) => {
            let resultCode=res.data.resultCode;
            if (resultCode==='noAuth'){
                alert('没有权限');
                window.location.href='/official-index.html';
            }
            if(resultCode !== 'busi_ex'){
                agreetoast.style.cssText="display: block;";
            }
        })
    }

};

maketure.onclick=function () {
    agreetoast.style.cssText="display: none;";
    window.location.href='/carrieroperatorlist.html';
};

agreeclose.onclick=function () {
    agreetoast.style.cssText="display: none;";
    window.location.href='/carrieroperatorlist.html';
};